using System;
using System.Runtime.Serialization;

namespace MonsterNet
{
	public class MNSharedFile : MNFSObject, ISerializable
	{
		protected DateTime _dateModified;
		private ulong _sizeInBytes;
		
		public DateTime DateModified {
			get {
				return this._dateModified;
			}
		}

		public ulong SizeInBytes {
			get {
				return this._sizeInBytes;
			}
		}

		public MNSharedFile (MNSynchronisedFile syncFile)
		{
			//copy across the syncFiles destination details.
			_name = syncFile.Name;
			_rootlessPath = syncFile.RootlessPath;
			
			_sizeInBytes = syncFile.GetSizeInBytesForLocation(MNFSObjectLocation.Destination);
			_dateModified = syncFile.GetDateModifiedForLocation(MNFSObjectLocation.Destination);
		}
		
		#region serialization
		private const string kSerialiseDateModified = "dm";
		private const string kSerialiseSizeInBytes = "s";
		
		public MNSharedFile(SerializationInfo info, StreamingContext ctxt) : base (info, ctxt) {
			_dateModified = info.GetDateTime(kSerialiseDateModified);
			_sizeInBytes = (ulong)info.GetValue(kSerialiseSizeInBytes, typeof(ulong));			
		}
		
		public new void GetObjectData(SerializationInfo info, StreamingContext ctxt) {
			base.GetObjectData(info, ctxt);	
			
			info.AddValue(kSerialiseDateModified, _dateModified);
			info.AddValue(kSerialiseSizeInBytes, _sizeInBytes);			
		}
		
		#endregion		
	}
}

